package testing;

import hypeerweb.*;

import static org.junit.Assert.*;

import org.junit.Test;

public class NodeTest 
{
	@Test
	public void test() 
	{
		
		Node tnode1 = new Node(3);
		Node tnode2 = new Node(11,5);
		Node tnode3 = new Node(15,2);
		Node tnode4 = new Node(6);
		Node tnode5	= new Node(6);
		Node tnode6 = new Node(3,10);
		Node tnode7 = new Node(11);
		
		
		assertTrue(tnode1.getId() != 4);
		assertTrue(tnode1.getId() == 3);
		assertTrue(tnode2.getId() == 11);
		
		assertTrue(tnode1.getNeighbors().isEmpty());
		
		tnode1.addNeighbor(tnode2);
		tnode1.addNeighbor(tnode3);
		tnode1.addNeighbor(tnode4);
		
		//tnode5 is a duplicate of tnode4
		tnode1.addNeighbor(tnode5);
		
		//find tnode2
		assertTrue(tnode1.getNeighbors().contains(tnode2));
		
		//make sure contains works with TreeSet
		assertTrue(tnode1.getNeighbors().contains(tnode4));
		assertTrue(tnode1.getNeighbors().contains(tnode5));
		
		//make sure there are only 3 nodes even though
		assertTrue(tnode1.getNeighbors().size()==3);
		
		//make sure remove works correctly
		tnode1.removeNeighbor(tnode2);
		assertTrue(!tnode1.getNeighbors().contains(tnode2));
		assertTrue(!tnode1.getNeighbors().isEmpty());
		tnode1.removeNeighbor(tnode3);
		tnode1.removeNeighbor(tnode4);
		assertTrue(tnode1.getNeighbors().isEmpty());
		
		assertTrue(tnode2.getWebId().toString().equals("01011"));
		assertTrue(tnode3.getWebId().toString().equals("1111"));
		
		assertTrue(tnode2.getHeight()==5);
		assertTrue(tnode6.getHeight()==10);
		
		tnode2.addDownPointer(tnode6);
		tnode2.addDownPointer(tnode5);
		tnode2.addDownPointer(tnode1);
		
		assertTrue(tnode2.getDownPointers().size()==2);
		tnode2.removeDownPointer(tnode4);
		assertTrue(tnode2.getDownPointers().size()==1);
		
		tnode2.addUpPointer(tnode6);
		tnode2.addUpPointer(tnode5);
		tnode2.addUpPointer(tnode1);
		
		assertTrue(tnode2.getUpPointers().size()==2);
		tnode2.removeUpPointer(tnode4);
		assertTrue(tnode2.getUpPointers().size()==1);
		
		tnode3.setWebId(tnode4.getWebId());
		assertTrue(tnode3.compareTo(tnode5)==0);
		assertTrue(tnode3.compareTo(tnode1)!=0);
		
		tnode3.setWebId(new WebId(7));
		tnode3.setFold(tnode4);
		assertTrue(tnode3.getFold().compareTo(tnode5)==0);
		tnode3.setFold(tnode2);
		assertTrue(tnode3.getFold().compareTo(tnode7)==0);
		
		tnode2.setSurrogateFold(tnode4);
		assertTrue(tnode2.getSurrogateFold().compareTo(tnode5)==0);
		tnode2.setSurrogateFold(tnode2);
		assertTrue(tnode2.getSurrogateFold().compareTo(tnode7)==0);
		
		tnode1.setInverseSurrogateFold(tnode4);
		assertTrue(tnode1.getInverseSurrogateFold().compareTo(tnode5)==0);
		tnode1.setInverseSurrogateFold(tnode2);
		assertTrue(tnode1.getInverseSurrogateFold().compareTo(tnode7)==0);
		
	
		
	}

}
